home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-16 | 1.9 KB | 83 lines | [TEXT/PJMM] |
- unit DateFKEY;
-
- { Types the current date when the user types cmd-shift-6. }
-
- interface
-
- procedure main;
-
- implementation
-
- procedure main;
-
- { ----------------------------- }
-
- function SendAString (theStr: str255): OSErr;
- const
- { keyMap is a subset of the KCHR System resource. }
- keyMap = 'ASDFHGZXCV*BQWERYT123465=97*80*OU*IP*LJ*K**,*NM';
- space = char(32);
- var
- i, keyCode: integer;
- theChar: char;
- theErr: OSErr;
- message, modifiers, modifierMask: longint;
- myQPtr: EvQElPtr;
- begin
- theErr := noErr;
- modifierMask := BitNot(shiftKey + cmdKey);
-
- if theStr <> '' then
- begin
- FlushEvents(keyDown, 0);
- for i := 1 to length(theStr) do
- begin
-
- { Get the proper keyCode from our keyMap. }
- theChar := theStr[i];
- if theChar in ['a'..'z'] then { Make theChar uppercase for our look-up string. }
- theChar := char(ord(theChar) - 32);
- if theChar = space then
- keyCode := $31
- else
- keyCode := pos(theChar, keyMap) - 1;
- if keyCode = -1 then
- keyCode := 0;
-
- { Assemble the message. }
- message := BitShift(keyCode, 8) + ord(theStr[i]);
-
- { Post the keyDown event. }
- theErr := PPostEvent(keyDown, message, myQPtr);
- if theErr <> noErr then
- leave;
-
- { Now strip off the cmdKey and shiftKey modifiers. }
- modifiers := BitAnd(myQPtr^.evtQModifiers, modifierMask);
- myQPtr^.evtQModifiers := modifiers;
- end;
- end;
- SendAString := theErr;
- end;
-
- { ============== main ============== }
-
- var
- dateStr: str255;
- tempLong: longint;
- begin
-
- { The queue can only hold 20 characters, }
- { so we strip off the day of the week. }
-
- GetDateTime(tempLong);
- IUDateString(tempLong, LongDate, dateStr);
- if dateStr <> '' then
- if pos(char(32), dateStr) > 0 then
- Delete(dateStr, 1, pos(char(32), dateStr));
-
- if SendAString(dateStr) <> noErr then
- SysBeep(10);
- end;
-
- end.